

#include "vector.h"

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

vm_vector vects[4];
int i;

vm_vector *vm_gram_schmidt_orth(vm_vector *, int);
void load_vects();
void generate_vects();

int main(int argc, char **argv){

  //load_vects();
  generate_vects();
  printf("Random vectors:\n");
  for ( i = 0; i < 3; i++){
    vm_println(vects[i]);
  }

  printf("Gram Schmidt ortho'ed vectors:\n");
  vm_vector *b = vm_gram_schmidt_orth(vects, 4);
  for ( i = 0; i < 4; i++){
    vm_println(b[i]);
  }

}

void load_vects(){

  FILE *f = fopen("../data/orthog.vec", "r");
  for ( i = 0; i < 3; i++){
    int ok = vm_read(f, &(vects[i]));
    if (!ok) {
      printf("Error reading vectors.\n");
      exit(1);
    }
  }
  fclose(f);

}

void generate_vects(){

  for ( i = 0; i < 4; i++){
    srand(time(NULL) + i);
    double x, y, z, w;
    x = rand() / (double)100000000;
    y = rand() / (double)100000000;
    z = rand() / (double)100000000;
    w = rand() / (double)100000000;
    vects[i].x = x;
    vects[i].y = y;
    vects[i].z = z;
    vects[i].w = w;
  }

}
